import 'package:flutter/material.dart';

import 'package:flutter_widgets_pc/widgets/button/kq_ink_well.dart';

import '../../resources/kq_theme_colors.dart';
import '../../theme/kq_theme_manager.dart';
import '../../utils/kq_multi_click_util.dart';

/// 通用圆角蓝色小按钮
///
/// @author 周卓
///
/// 字体12，水平边距8，垂直边距6，背景蓝色，文字白色，宽高自适应
///
/// 常用场景：获取验证码，详情Item里的查看、编辑，自动生成计划单号、任务单号等。
class KqSmallButton extends StatelessWidget {
  /// 按钮文字
  final String title;

  /// 字体大小，默认12
  final double? fontSize;

  /// 圆角，默认2
  final double? radius;

  /// 文字颜色，默认白色
  final Color? textColor;

  /// 背景颜色，默认主题色
  final Color? bgColor;

  /// 水平内边距，默认8
  final double? horizontalPadding;

  /// 垂直内边距，默认6
  final double? verticalPadding;

  /// 是否置灰
  final bool disabled;

  /// 是否可点击
  final Function(bool disabled)? onTap;

  const KqSmallButton(
      {Key? key,
      required this.title,
      this.disabled = false,
      this.onTap,
      this.bgColor,
      this.textColor,
      this.fontSize,
      this.radius,
      this.horizontalPadding,
      this.verticalPadding})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return KqInkWell(
      onTap: () {
        if (KqMultiClickUtil.isMultiClick()) {
          return;
        }
        if (onTap != null) {
          onTap!(disabled);
        }
      },
      backgroundColor: bgColor ??
          (disabled
              ? KqThemeColors.bgD
              : (KqThemeManager.getButtonConfig()
                      .smallBtnBgColor ??
              KqThemeManager.getCommonConfig().mainColor ?? KqThemeColors.bgBlue)),
      horizontalPadding: horizontalPadding ?? 8,
      verticalPadding: verticalPadding ?? 6,
      radius: radius ?? 2,
      child: Align(
        alignment: Alignment.center,
        child: Text(
          title,
          style: TextStyle(
            color: textColor ?? KqThemeManager.getButtonConfig().smallBtnTextColor ?? KqThemeColors.textWhite,
            fontSize: fontSize ?? 12,
            fontWeight: FontWeight.normal,
          ),
        ),
      ),
    );
  }
}
